home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9203.ZIP / DRVMONIT.ZIP / LOGINIT.ASM < prev    next >
Assembly Source File  |  1991-11-29  |  10KB  |  244 lines

  1. ;---------------------------------------------------------------    
  2. ;loginit - initialization code for device driver monitor       |
  3. ;--------------------------------------------------------------|
  4. ;Copyright 1990, 1992 ASMicro Co.                              |
  5. ;--------------------------------------------------------------|
  6. ;                                                              |
  7. ; 4/15/90                      Rick Knoblaugh                  |
  8. ;--------------------------------------------------------------|
  9. ;include files                                                 |
  10. ;---------------------------------------------------------------    
  11.                 include logequ.inc
  12.                 include logstruc.inc
  13.  
  14.  
  15. code            segment public  'CODE'
  16.                 assume cs:code, ds:code, es:code
  17. ;--------------------------------------------------------------
  18. ;PUBLIC                                                       |
  19. ;--------------------------------------------------------------
  20.                 public  drv_init
  21.  
  22. ;--------------------------------------------------------------
  23. ;EXTERNALS                                                    |
  24. ;--------------------------------------------------------------
  25.                 extrn   req_header:dword
  26.                 extrn   get_key:near
  27.                 extrn   monitor_process:near
  28.                 extrn   save_patch:word
  29.                 extrn   patch_flag:byte
  30.                 extrn   old_user_int:dword
  31.                 extrn   drv_state:word
  32.  
  33. ;--------------------------------------------------------------
  34. ;drv_init - Perform driver initialization.  Parse command     |
  35. ;           line for switch.  Take over user interrupt        |
  36. ;           for gaining control from another device driver.   |
  37. ;--------------------------------------------------------------
  38. drv_init        proc    near
  39.                 mov     dx, offset sign_on1 
  40.                 mov     ah, DOS_PRINT_STRING
  41.                 int     21h
  42.  
  43.                 mov     patch_flag, FALSE       ;default to no patching
  44.  
  45.                 push    ds              
  46.                 lds     si, req_header
  47.                 lds     si, [si].cmd0_bpb_ptr   ;ptr to cmd line
  48.                 call    val_switch              ;return carry if invalid
  49.                 pop     ds
  50.                 jnc     drv_i500
  51.                 xor     dx, dx                  ;error, keep no code    
  52.                 mov     ax, ERR_GENFAIL         ;return status
  53.                 jmp     short drv_i800
  54.  
  55.  
  56.  
  57. drv_i500:
  58.  
  59.                 push    ds
  60.                 pop     es
  61.                 mov     bx, USER_INT            ;interrupt to take over
  62.                 mov     di, offset old_user_int ;place to store previous isr
  63.                 mov     dx, offset monitor_process ;new isr
  64.                 call    get_int                     
  65.                 mov     dx, offset drv_init     ;drop code after this
  66.                 mov     ax, OK_STATUS           ;return status
  67.                 mov     drv_state, EXPECT_STRAT
  68.  
  69. drv_i800:
  70.                 les     di, req_header
  71.                 mov     es:[di].cmd0_eadrs_off, dx
  72.                 mov     es:[di].cmd0_eadrs_seg, cs
  73.  
  74.  
  75.                 ret
  76.  
  77.  
  78. sign_on1        db      'Device Driver Monitor   Version 1.0', CR, LF
  79.                 db      'Copyright ASMicro Co. 1990, 1992', CR, LF , CR, LF, '$'
  80.  
  81. bad_swtch_msg   db      'Invalid switch - driver not loaded', CR, LF, CR, LF 
  82.                 db      'Press any key to exit...', CR, LF, CR, LF, '$'
  83. drv_init        endp        
  84.  
  85. ;--------------------------------------------------------------
  86. ;get_int - For a given interrupt vector, store contents and   |
  87. ;          load with new isr address.                         |
  88. ;                                                             |
  89. ;          bx = int number                                    |
  90. ;          es:di = location to store contents                 |
  91. ;          dx = offset new isr                                |
  92. ;--------------------------------------------------------------
  93. get_int         proc    near
  94.                 push    ds
  95.                 xor     ax, ax
  96.                 mov     ds, ax
  97.                 shl     bx, 1
  98.                 shl     bx, 1
  99.                 mov     ax, [bx]
  100.                 stosw                
  101.                 mov     ax, [bx].d_segment
  102.                 stosw          
  103.                 cli
  104.                 mov     [bx].d_offset, dx
  105.                 mov     [bx].d_segment, cs
  106.                 pop     ds
  107.                 sti
  108.                 ret
  109. get_int         endp        
  110.  
  111. ;--------------------------------------------------------------
  112. ;val_switch - Search command line.  Values expected are as    |
  113. ;             follows:                                        |
  114. ;                                                             |
  115. ;                     /Pxxxx                                  |
  116. ;                                                             |
  117. ;         where xxxx are 4 hex digits representing the bytes  |
  118. ;         of code that were overlaid when the user patched    |
  119. ;         in the int xx instruction which gives this program  |
  120. ;         control.                                            |
  121. ;                                                             |
  122. ;         If the switch is present and invalid, report it     |
  123. ;         to user and set carry flag.  If valid values are    |
  124. ;         found save them.                                    |
  125. ;                                                             |
  126. ;         Enter:  ds:si pointing after "device=".             |
  127. ;                                                             |
  128. ;--------------------------------------------------------------
  129. val_switch      proc    near
  130.  
  131.  
  132.                 mov     cx, MAX_CMD_LINE
  133. val_s100:
  134.                 lodsb                           
  135.                 cmp  al, LF
  136.                 je      val_s500                ;no cmd tail
  137.                 cmp  al, CR
  138.                 je      val_s400                ;parms, but not right
  139.                 cmp  al, SWITCH_CHAR
  140.                 loopne  val_s100                ;go get switch
  141.  
  142. val_s200:       
  143.                 lodsb                           
  144.                 and     al, 0dfh                ;force to upper case
  145.                 cmp     al, PATCH_SWITCH
  146.                 jne     val_s400                ;if not valid, report it
  147.  
  148.                 call    skip_white_sp
  149.                 jcxz    val_s400                ;report bad switch               
  150.  
  151.  
  152.                 mov     di, si                  ;save start of patch codes
  153.                 mov     cx, NUM_PATCH_BYTES
  154. val_s300:
  155.                 lodsb
  156.                 cmp     al, 'a'
  157.                 jb      val_s340
  158.                 and     al, 0dfh                ;force to upper case
  159.                 mov     [si - 1], al
  160. val_s340:
  161.                 cmp     al, '0'                 ;within valid range for code?
  162.                 jb      val_s400                ;report bad value
  163.                 cmp     al, 'F'                 
  164.                 ja      val_s400                ;report bad value
  165.                 cmp     al, 'A'                 
  166.                 jae     val_s350                ;ok
  167.                 cmp     al, '9'
  168.                 ja      val_s400                ;report bad value
  169. val_s350:
  170.                 loop    val_s300
  171.                 mov     si, di                  ;get back to start of digits
  172.                 push    cs
  173.                 pop     es                      ;get our ds in es
  174.  
  175.                 mov     di, offset cs:save_patch
  176.  
  177.                 mov     cx, NUM_PATCH_BYTES / 2 ;convert both sets of two digits
  178.  
  179. val_s380:
  180.                 lodsb                           ;get a digit of patch code
  181.                 call    asc2bin                 ;return binary value in al
  182.                 shl     al, 1                                              
  183.                 shl     al, 1                                              
  184.                 shl     al, 1                                              
  185.                 shl     al, 1                                              
  186.                 mov     dl, al                  
  187.                 lodsb                           ;get a digit of patch code
  188.                 call    asc2bin                 ;return binary value in al
  189.                 add     al, dl
  190.                 stosb                           ;save first byte of patch code
  191.                 loop    val_s380
  192.                 mov     cs:patch_flag, TRUE     ;indicate that user patched
  193.  
  194.                 jmp     short val_s500
  195.  
  196. val_s400:
  197.                 push    cs
  198.                 pop     ds                     ;get our ds
  199.                 mov     dx, offset bad_swtch_msg
  200.                 mov     ah, DOS_PRINT_STRING
  201.                 int     21h
  202.                 call    get_key
  203.                 stc
  204.                 jmp     short val_s999
  205.  
  206. val_s500:                       
  207.                 
  208.                 clc                             ;no errors
  209. val_s999:
  210.                 ret
  211. val_switch      endp       
  212.                 
  213.  
  214. asc2bin         proc    near
  215.                 cmp     al, '9'                 ;see if 0-9 or A-F
  216.                 ja      asc2b_500
  217.                 sub     al, '0'                 ;convert to binary
  218.                 jmp     short asc2b_900
  219. asc2b_500:
  220.                 sub     al, 'A' - 10
  221.  
  222. asc2b_900:
  223.                 ret
  224. asc2bin         endp        
  225.  
  226.  
  227.  
  228. skip_white_sp   proc    near
  229.                 cmp     byte ptr [si], ' '
  230.                 je      skip_w200
  231.                 cmp     byte ptr [si], TAB
  232.                 jne     skip_w900
  233.  
  234. skip_w200:
  235.                 inc     si
  236.                 loop    skip_white_sp
  237. skip_w900:
  238.                 ret
  239. skip_white_sp   endp
  240.  
  241.  
  242. code            ends
  243.                 end
  244.